/*
  Trajectories associated to one object along the time.
*/
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;

class ObjectLog{
    
    protected String id_object;
    protected HashMap v_trajectories; //AssociatedTrajectory stored in the HashMap
    
    public float normality_degree = 1;
    

    public ObjectLog(String id){
	this.id_object = id;
	v_trajectories = new HashMap();
    }

    public float getNormalityDegree(){return this.normality_degree;}

    public boolean isAssociatedTrajectory(Trajectory t){
	AssociatedTrajectory at = (AssociatedTrajectory) this.v_trajectories.get(t.getId());
	if(at != null)
	    return true;
	else
	    return false;
    }//end method

    public HashMap getAssociatedTrajectories(){return this.v_trajectories;}
    public void associateTrajectory(String key, AssociatedTrajectory at){
	this.v_trajectories.put(key, at);
    }

    public void removeAssociatedTrajectory(String key){
	this.v_trajectories.remove(key);
    }

    public void updateNormalityDegree(){
	
	Iterator it = v_trajectories.entrySet().iterator();
	float max = 0;

	while (it.hasNext()) {
	    Map.Entry e = (Map.Entry)it.next();
	    AssociatedTrajectory at = (AssociatedTrajectory) e.getValue();
	    float tmp = at.rol_satisfaction;
	    
	    if(tmp > at.spatial_satisfaction){
		tmp = at.spatial_satisfaction;		
	    }
	    if(tmp > at.temporal_satisfaction)
		tmp = at.temporal_satisfaction;

	    if (tmp > max)
		max = tmp;
	}
	this.normality_degree = max;
    }//end updateNormalityDegree
}//end class
